import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { SPetArenaInfos } from "../../../../../Message/Game/SPetArenaInfos";
import { PetArenaRewardConfig } from "../../../resource/PetArenaRewardConfig";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { SPlayerPetArenaEx } from "../../../../../Message/Game/SPlayerPetArenaEx";
import { ItemData } from "../../../resource/info/ItemData";
import { PetCpnRewardUtil } from "./info/PetCpnRewardUtil";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { ObjCreate } from "../../common/ObjCreate";
import { TilePanel } from "../../equipment/TilePanel";
import { PetCpnDrRenderder } from "./PetCpnDrRenderder";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { PetCpnRankRewardItem } from "./PetCpnRankRewardItem";
import { ImagesConst } from "../../../resource/ImagesConst";
import { BaseItem } from "../../common/BaseItem";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { EPetArenaReward } from "../../../../../Message/Game/EPetArenaReward";
import { FlyToNavbarTool } from "../../award/FlyToNavbarTool";
import { EPetArenaSearch } from "../../../../../Message/Game/EPetArenaSearch";
import { Cache } from "../../../cache/Cache";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { PetArenaRewardInfo } from "../../../resource/info/PetArenaRewardInfo";
import { _EPetArenaRewardRank } from "../../../../../EPetArenaReward/_EPetArenaRewardRank";
import { _EPetArenaSearchRward } from "../../../../../EPetArenaSearch/_EPetArenaSearchRward";
type int = number;
//class PetCpnDayRewardWindow
    
    export  class PetCpnDayRewardWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this.setSize(610, 420);
            this.title = Language.getString(54676);
            this.titleHeight = 28;
            return;
        }

        public updateTop3(arg1: SPetArenaInfos): void
        {
            var loc3=null;
            var loc1=[];
            var loc2=PetArenaRewardConfig.instance.getTop3Rewards();
            var loc4=new Map<any, any> /* flash.utils.Dictionary */();
            if (arg1) 
            {
                loc3 = arg1.petArenaInfos;
                loc1.push({"reward": loc2[0], "arenaInfo": loc3[1]});
                loc1.push({"reward": loc2[1], "arenaInfo": loc3[0]});
                loc1.push({"reward": loc2[2], "arenaInfo": loc3[2]});
            }
            this._itemListPanel.dataProvider = new DataProvider(loc1);
            return;
        }

        public updateByArenaEx(arg1: SPlayerPetArenaEx): void
        {
            if (arg1) 
            {
                this._pRankTxt.text = arg1.lastRank.toString();
                this._lastRewardInfo = PetArenaRewardConfig.instance.getPetArenaRewardInfo(arg1.lastRank);
                if (this._lastRewardInfo) 
                {
                    this._rItem.itemData = this._lastRewardInfo.itemDataArray[0] as ItemData;
                    if (this._lastRewardInfo.itemDataArray.length > 1) 
                    {
                        this._rItem1.itemData = this._lastRewardInfo.itemDataArray[1] as ItemData;
                    }
                    if (this._lastRewardInfo.reward) 
                    {
                        this._rewardTxt.htmlText = "+" + PetCpnRewardUtil.getStrByReward(this._lastRewardInfo.reward, "", false);
                    }
                }
                this._getBtn.enabled = arg1.rewardStatus > 0;
            }
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            super.createChildren();
            loc1 = new GTextFormat(FontUtil.xingkaiName, 22, 65280);
            ObjCreate.createBg(17, 39, 380, 224, this);
            this._itemListPanel = new TilePanel();
            this._itemListPanel.setSize(360, 185);
            this._itemListPanel.columnWidth = 120;
            this._itemListPanel.rowHeight = 185;
            this._itemListPanel.setStyle("cellRenderer", PetCpnDrRenderder);
            this._itemListPanel.move(30, 75);
            this.addChild(this._itemListPanel);
            this._lSprite = new Object /* flash.display.Sprite */();
            this._lSprite.x = 17;
            this._lSprite.y = 265;
            this.addChild(this._lSprite);
            ObjCreate.createBg(0, 0, 380, 145, this._lSprite);
            this._rewards = PetArenaRewardConfig.instance.get4LaterRewards();
            var loc4=0;
            while (loc4 < this._rewards.length) 
            {
                if (loc4 != 0) 
                {
                    if (loc4 != 1) 
                    {
                        loc3 = GlobalStyle.textFormatGreen;
                    }
                    else 
                    {
                        loc3 = GlobalStyle.textFormatBlue;
                    }
                }
                else 
                {
                    loc3 = GlobalStyle.textFormatPurple;
                }
                loc2 = new PetCpnRankRewardItem("", loc3);
                loc2.updateReward(this._rewards[loc4]);
                loc2.x = 13;
                loc2.y = 5 + loc4 * 20;
                this._lSprite.addChild(loc2);
                ++loc4;
            }
            this._rSprite = new Object /* flash.display.Sprite */();
            this._rSprite.x = 400;
            this._rSprite.y = 39;
            this.addChild(this._rSprite);
            ObjCreate.createBg(0, 0, 192, 371, this._rSprite);
            ObjCreate.createBg(1, -2, 192, 30, this._rSprite, ImagesConst.RbListHeader);
            ObjCreate.createBg(40, 85, 115, 35, this._rSprite, ImagesConst.SelectedBg);
            this._pRankTxt = ObjCreate.createTextField("", 40, 90, 115, 30, this._rSprite, loc1);
            this._pRankTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            ObjCreate.createBg(10, 143, 168, 2, this._rSprite, ImagesConst.SplitLine);
            ObjCreate.createBg(12, 165, 38, 38, this._rSprite, ImagesConst.PackItemBg);
            this._rItem = new BaseItem();
            this._rItem.setSize(32, 32);
            this._rItem.move(14, 167);
            this._rSprite.addChild(this._rItem);
            ObjCreate.createBg(57, 165, 38, 38, this._rSprite, ImagesConst.PackItemBg);
            this._rItem1 = new BaseItem();
            this._rItem1.setSize(32, 32);
            this._rItem1.move(59, 167);
            this._rSprite.addChild(this._rItem1);
            this._rewardTxt = ObjCreate.createTextField("", 110, 175, 200, 20, this._rSprite, GlobalStyle.textFormatOrange);
            ObjCreate.createBg(10, 225, 168, 2, this._rSprite, ImagesConst.SplitLine);
            this._getBtn = ObjCreate.createGButton(Language.getString(20424), 60, 280, 70, 24, this._rSprite, "ButtonRed");
            this._getBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGetBtnClickHandler);
            this._tipTxt = ObjCreate.createTextField(Language.getString(54682), 0, 345, 192, 20, this._rSprite, GlobalStyle.textFormatGreen);
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            LoaderHelp.addResCallBack(ResFileConst.petCpnReward, this.onLoadHandler);
            return;
        }

        /* internal  */updateListData(arg1: Array<any>): void
        {
            this._itemListPanel.dataProvider = new DataProvider(arg1);
            return;
        }

        /* internal  */onLoadHandler(): void
        {
            ObjCreate.createBitmap(ImagesConst.PetCpnRank2, 65, 50, this);
            ObjCreate.createBitmap(ImagesConst.PetCpnRank1, 185, 50, this);
            ObjCreate.createBitmap(ImagesConst.PetCpnRank3, 305, 50, this);
            ObjCreate.createBitmap(ImagesConst.PetCpnRewardGetLabel, 60, 4, this._rSprite);
            ObjCreate.createBitmap(ImagesConst.PetCpnPreRankLabel, 40, 55, this._rSprite);
            return;
        }

        /* internal  */onGetBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetCpnGetReward, {"type": _EPetArenaRewardRank, "callBackFun": this.getRewardSuccess}));
            return;
        }

        /* internal  */getRewardSuccess(): void
        {
            if (this._rItem.itemData) 
            {
                FlyToNavbarTool.flyToBackPack(this._rItem.bitmapdata, this._rItem.localToGlobal(new Object /* flash.geom.Point */(2, 2)));
            }
            if (this._rItem1.itemData) 
            {
                FlyToNavbarTool.flyToBackPack(this._rItem1.bitmapdata, this._rItem1.localToGlobal(new Object /* flash.geom.Point */(2, 2)));
            }
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetCpnSearch, {"searchType": _EPetArenaSearchRward, "perPage": 3, "targetPage": 1}));
            this.updateByArenaEx(Cache.instance.petCompetition.petArenaEx);
            return;
        }

        /* internal */ /* var */_itemListPanel: TilePanel;

        /* internal */ /* var */_lSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_rSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_pRankTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_rItem: BaseItem;

        /* internal */ /* var */_rItem1: BaseItem;

        /* internal */ /* var */_rewardTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_getBtn: GButton;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_rewards: Array<any>;

        /* internal */ /* var */_lastRewardInfo: PetArenaRewardInfo;
    }
